package model

type TreeSelect struct {
	Id       int64         `json:"id"`       // 节点ID
	Label    string        `json:"label"`    // 节点名称
	Children []*TreeSelect `json:"children"` // 子节点
}

func NewTreeSelectByDept(dept *Dept) *TreeSelect {
	deptTreeData := &TreeSelect{
		Id:    dept.Id,
		Label: dept.DeptName,
	}
	// 子节点
	children := dept.Children
	if len(children) > 0 {
		var treeList []*TreeSelect
		for _, child := range children {
			// 递归生成子节点的TreeSelect
			childTree := NewTreeSelectByDept(child)
			treeList = append(treeList, childTree)
		}
		deptTreeData.Children = treeList
	}
	return deptTreeData
}

func NewTreeSelectByMenu(menu *SysMenu) *TreeSelect {
	menuTreeData := &TreeSelect{
		Id:    menu.Id,
		Label: menu.MenuName,
	}
	// 子节点
	children := menu.Children
	if len(children) > 0 {
		var treeList []*TreeSelect
		for _, child := range children {
			// 递归生成子节点的TreeSelect
			childTree := NewTreeSelectByMenu(child)
			treeList = append(treeList, childTree)
		}
		menuTreeData.Children = treeList
	}

	return menuTreeData
}

// RoleMenuTreeSelect 角色菜单treeSelect
type RoleMenuTreeSelect struct {
	CheckedKeys []int64       `json:"checkedKeys"` // 选中节点ID
	Menus       []*TreeSelect `json:"menus"`       // 菜单
}
